package com.csvreader.rss;

import java.io.IOException;
import java.net.URL;
import java.util.List;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

public class RssRead {
	public static void main(String[] args) 
            throws InstantiationException, ClassNotFoundException, 
            IllegalAccessException {

	      String file = "E:/sipxml/sip.xml";
	      String url = "http://iyanlei.com/feed";
	      
	    SAXBuilder builder = new SAXBuilder();
	    try {
	     Document doc = builder.build(new URL(url));
	      Element root=doc.getRootElement();
	       Element  el=root.getChild("channel"); //rss2.0
	       List listitem=el.getChildren("item");//rss2.0
	      System.out.println("共有="+listitem.size());
	      for(int i=0;i<listitem.size();i++)
	      {
	        Element e = (Element)listitem.get(i);       
	       System.out.println("title="+e.getChildText("title"));
	       System.out.println("link="+e.getChildText("link"));
	       System.out.println("category="+e.getChildText("category"));
	       System.out.println("description="+e.getChildText("description"));
	       System.out.println("time = "+e.getChildText("pubDate"));
	       System.out.println();
	       System.out.println();
	 
	 }
	    }catch (JDOMException e){
	        e.printStackTrace();
	    }catch (IOException e){
	        e.printStackTrace();
	    }


    }
}
